"ui";
importClass(android.graphics.Color);
importClass(android.graphics.drawable.GradientDrawable);
// 数据
var storage = storages.create("autotouchHongshu");
// 库
const project = require('./project.json');

//参数声明
var isPulic = true;
var appPackageName = "com.xingin.xhs";
var deviceWidth = device.width;
var deviceHeight = device.height;
var anquanqu = deviceHeight - 200;
var picJizhunWidth = 1;
var picJizhunHeight = 1;
var version = project.versionName;
var yanchi = 500; // 点击后停顿
var yanchi1 = 1000; // 点击前停顿
var yanchi2 = 2000; // 点击后停顿
var yanchi3 = 3000; // 点击后停顿
var yanchi5 = 5000; // 点击后停顿

var floatyConsole;
var myLogStr = "";
var searchForList = "";
var pinglunsList = "";
var pinglunsListStr = "";
var pinglunReg = "";
var sixinCont = "";
var sixinReg = "";
var sousuofanye = 5;
var pinglunfanye = 5;
var plxl = 50;

log('分辨率：', deviceWidth, deviceHeight)
ui.layout(
    <ScrollView>
        <vertical>
            <appbar>
                <toolbar id="appTitle" title="红薯软件" />
            </appbar>
            <Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}" padding="8 8 8 8" textSize="15sp" />
            <horizontal>
                <text text="  激活码：" gravity="left" />
                <input id="jihuoma" hint="请输入注册码" textSize="15sp" inputType="text" gravity="left" w="*" />
            </horizontal>
            {/* <horizontal>
                <text text="  小红书" gravity="left" />
            </horizontal> */}
            <vertical marginTop="8sp" bg="#99FE01">
                <horizontal>
                    <text text="  评论过滤模式：" gravity="left" />
                    <spinner id="glms" entries="评论包含关键词" />
                </horizontal>
                <horizontal>
                    <text text="  搜索内容：" gravity="left" />
                    <input id="searchFor" hint="请填写搜索词！" textSize="15sp" gravity="left" w="*" />
                </horizontal>
                <horizontal >
                    <text text="  私信关键词：" gravity="left" />
                    <input id="sixinKeys" hint="多个用|分割，空表示不过滤" textSize="15sp" gravity="left" w="*" />
                </horizontal>
                <horizontal>
                    <text text="  私信内容：" gravity="left" />
                    <input id="sixinCont" hint="请填写私信内容！" textSize="15sp" gravity="left" w="*" />
                </horizontal>
                <horizontal >
                    <text text="  评论关键词：" gravity="left" />
                    <input id="pinglunKeys" hint="多个用|分割，空表示不过滤" textSize="15sp" gravity="left" w="*" />
                </horizontal>
                <horizontal marginTop="6sp">
                    <text text="  评论内容：" gravity="left" />
                    <input id="pingluns" hint="请填写回复评论的内容,分割！" textSize="15sp" gravity="left" w="*" />
                </horizontal>
                <horizontal>
                    <text text="  搜索区最多翻页：" gravity="left" />
                    <input id="sousuofanye" hint="搜索区翻页" textSize="15sp" inputType="number" gravity="center" />
                </horizontal>
                <horizontal>
                    <text text="  评论区最多翻页：" gravity="left" />
                    <input id="pinglunfanye" hint="评论区翻页" textSize="15sp" inputType="number" gravity="center" />
                </horizontal>
            </vertical>

            <horizontal marginTop="10sp" padding="12sp" bg="#FFFF01">
                <checkbox id="isPinglun" text="评论回复" />
                <checkbox id="isSixin" text="私信" />
                <checkbox id="isGuanzhu" text="关注" />
            </horizontal>

            <horizontal marginTop="6sp">
                <text text="  评论限量：" gravity="left" />
                <input id="plxl" hint="评论限量" textSize="15sp" inputType="number" gravity="center" />
                <text text="    喜欢概率：" gravity="left" />
                <input id="xhgl" hint="喜欢概率" textSize="15sp" inputType="number" gravity="center" />
            </horizontal>
            +
            <horizontal marginTop="10sp" padding="12sp" bg="#FFC801">
                <checkbox id="logWindow" text="日志窗口" />
                <checkbox id="logFile" text="日志文件" />
            </horizontal>
            <horizontal marginTop="6sp">
                <text text="  浏览作品：" gravity="left" />
                <text id="liulanNum" text="88" gravity="left" />
                <text text="   ----" gravity="center" />
                <text text="  评论内容：" gravity="left" />
                <text id="pinglunNum" text="888" gravity="left" />
                <button id="cleanCon" text="重置" marginLeft="6sp" />
                <button id="cleanApp" text="初始化" marginLeft="6sp" />
            </horizontal>
            <horizontal marginTop="6sp">
                <button id="start" text="开始运行" layout_weight="1" style="Widget.AppCompat.Button.Colored" />
            </horizontal>
            <text text="   温馨提示：" gravity="left" marginTop="6sp" />
            <text text="   1.软件根据搜索词搜索对应内容；" gravity="left" />
            <text text="   2.在作品评论区用设置的关键词进行匹配；" gravity="left" />
            <text text="   3.可设置多个关键词，分隔符“|”；" gravity="left" />
            <text text="   4.可多选设置回复评论，回复点赞和私信" gravity="left" />
            <text text="   5.红薯禁言严重欲速则不达，请谨慎设置数量" gravity="left" />
            <horizontal marginTop="6sp">
                <text id="appVersion" text="   当前软件版本：" gravity="left" />
                <text id="androidVer" text="   本机安卓版本：" />
            </horizontal>

        </vertical>
    </ScrollView>
);

ui.androidVer.text("   本机安卓版本：" + device.release + "");
ui.appVersion.text("   当前软件版本：" + version + "     ");
ui.appTitle.title = "红薯引流辅助 V" + version;
ui.autoService.on("check", function (checked) {
    if (checked && auto.service == null) {
        app.startActivity({
            action: "android.settings.ACCESSIBILITY_SETTINGS"
        });
    }
    if (!checked && auto.service != null) {
        auto.service.disableSelf();
    }
});


//记录按键被按下时的触摸坐标
var x = 0, y = 0;
//记录按键被按下时的悬浮窗位置
var windowX, windowY;
// 悬浮窗
var floatyWindow;

function xuanfuFunc() {
    log('开启悬浮窗')
    floatyWindow = floaty.window(
        <horizontal >
            <button id="floatyAction" text="运" textSize="12sp" w="35" h="35"></button>
            <button id="mySet" text="设置" textSize="12sp" w="40" h="35" bg="#87CFE8" marginLeft="8sp" />
            <button id="myExit" text="退出" textSize="12sp" w="40" h="35" bg="#02FE99" marginLeft="2sp" />
        </horizontal >
    );

    floatyWindow.floatyAction.setOnTouchListener(function (view, event) {
        switch (event.getAction()) {
            case event.ACTION_DOWN:
                x = event.getRawX();
                y = event.getRawY();
                windowX = floatyWindow.getX();
                windowY = floatyWindow.getY();
                return true;
            case event.ACTION_MOVE:
                //移动手指时调整悬浮窗位置
                floatyWindow.setPosition(windowX + (event.getRawX() - x), windowY + (event.getRawY() - y));
                return true;
            case event.ACTION_UP:
                //手指弹起时如果偏移很小则判断为点击
                if (Math.abs(event.getRawY() - y) < 5 && Math.abs(event.getRawX() - x) < 5) {
                    floatyActionOnClick();
                }
                return true;
        }
        return true;
    });

    floatyWindow.mySet.setVisibility(8);
    floatyWindow.myExit.setVisibility(8);
    setBackgroundRoundRounded(floatyWindow.floatyAction, true);

    floatyWindow.mySet.on("click", function () {
        app.launchPackage("com.daoyikeji.xiaohongshuZdh");
    })

    floatyWindow.myExit.on("click", function () {
        threads.shutDownAll()
        ui.finish()
    })
}

function setBackgroundRoundRounded(view, bloo) {
    gradientDrawable = new GradientDrawable();
    gradientDrawable.setShape(GradientDrawable.RECTANGLE);
    if (bloo) {
        gradientDrawable.setColor(Color.GREEN);
    } else {
        gradientDrawable.setColor(Color.RED);
    }
    gradientDrawable.setCornerRadius(80);
    view.setBackground(gradientDrawable);
}

// 左上角点击
function floatyActionOnClick() {
    if (floatyWindow.floatyAction.getText() == '运') {
        setBackgroundRoundRounded(floatyWindow.floatyAction, false);
        floatyWindow.mySet.setVisibility(0);
        floatyWindow.myExit.setVisibility(0);
        floatyWindow.floatyAction.setText('停');
        storage.put("zanting", true);
        toastLog("停止");
    } else {
        floatyWindow.mySet.setVisibility(8);
        floatyWindow.myExit.setVisibility(8);
        setBackgroundRoundRounded(floatyWindow.floatyAction, true);
        floatyWindow.floatyAction.setText('运');
        storage.put("zanting", false);
        toastLog("运行")
    }
}

// 打印输出
function myLogFunc() {
    log(arguments)
    myLogStr += '\n' + String(arguments[0])
    //对控件的操作需要在UI线程中执行
    ui.run(function () {
        floatyConsole.myLog.text(" " + myLogStr + " ");
    });
    // let zanting = storage.get("zanting", false);
    // while (zanting) {
    //     zanting = storage.get("zanting", false);
    //     sleep(2000)
    // }
}

// 窗口
function xuanfuLogFunc() {
    floatyConsole = floaty.rawWindow(
        <frame gravity="left">
            <text id="myLog" text="日志" textColor="#ffffff" alpha="0.6" bg="#000000" textSize="10sp" ellipsize="marquee" gravity="bottom" />
        </frame>
    );
    let w = 358 * picJizhunWidth;
    let h = 200 * picJizhunHeight;
    floatyConsole.setSize(w, h)
    floatyConsole.setPosition(5, deviceHeight - h - h);
    floatyConsole.setTouchable(false)
    floatyConsole.myLog.text(" " + myLogStr + " ");
}

// 保存配置
function saveconfig() {
    storage.put("jihuoma", ui.jihuoma.text());
    storage.put("searchFor", ui.searchFor.text());
    storage.put("sixinCont", ui.sixinCont.text());
    storage.put("sixinKeys", ui.sixinKeys.text());
    storage.put("pinglunKeys", ui.pinglunKeys.text());
    storage.put("pingluns", ui.pingluns.text());
    storage.put("isPinglun", ui.isPinglun.checked);
    storage.put("isSixin", ui.isSixin.checked);
    storage.put("isGuanzhu", ui.isGuanzhu.checked);
    storage.put("logFile", ui.logFile.checked);
    storage.put("logWindow", ui.logWindow.checked);
    storage.put("plxl", ui.plxl.text());
    storage.put("xhgl", ui.xhgl.text());
    storage.put("pinglunfanye", ui.pinglunfanye.text());
    storage.put("sousuofanye", ui.sousuofanye.text());
    log('已保存配置')
}

function readconfig() {
    ui.jihuoma.text(storage.get("jihuoma", "3XICJJ9M1MF7YVP17Q6P6SPQTBJC"));
    ui.searchFor.text(storage.get("searchFor", "复合"));
    ui.sixinCont.text(storage.get("sixinCont", "诚信来互有赞必回随迟必到，欢迎来互！"));
    ui.sixinKeys.text(storage.get("sixinKeys", "有票|嘎嘎活"));
    ui.pinglunKeys.text(storage.get("pinglunKeys", "求求了|师傅|帮我|做了|推荐"));
    ui.pingluns.text(storage.get("pingluns", "确实有用但是最好是找线下的师傅，我也是朋友推荐才去做的,试试xuan，我是线下面对面弄得，大概十几天吧，他主动联系我，网上弄得内些都没用。,之前我点的师傅特别厉害一路上坑很多但是遇上了真的超级厉害"));
    ui.isPinglun.checked = Boolean(storage.get("isPinglun", true));
    ui.logFile.checked = Boolean(storage.get("logFile", false));
    ui.logWindow.checked = Boolean(storage.get("logWindow", true));
    ui.isSixin.checked = Boolean(storage.get("isSixin", false));
    ui.isGuanzhu.checked = Boolean(storage.get("isGuanzhu", false));
    ui.plxl.text(storage.get("plxl", "50"));
    ui.xhgl.text(storage.get("xhgl", "60"));
    ui.pinglunfanye.text(storage.get("pinglunfanye", "5"));
    ui.sousuofanye.text(storage.get("sousuofanye", "5"));
    ui.liulanNum.text(String(storage.get("liulanNum", "0")));
    ui.pinglunNum.text(String(storage.get("pinglunNum", "0")));
    log("读取本地配置")
}
// 直接读取存贮值
readconfig()
// 请求服务器
function autoServerFunc() {
    myLogFunc("注册服务")
    let req = http.postJson("http://123.60.43.199:8866/main/v1/auto/xhsYl", {
        activationCode: storage.get("jihuoma", ""),
        aap: "xhsYl",
        deviceWidth: device.width,
        deviceHeight: device.height,
        brand: device.brand,
        versionCode: project.versionCode,
        release: device.release,
        sdkInt: device.sdkInt,
        androidId: device.getAndroidId(),
        fingerprint: device.fingerprint,
        // mac: device.getMacAddress(), //雷电5崩溃
        // iMEI: device.getIMEI(), // 需要权限 否则报错
        startTime: new Date().getTime()
    });
    let rJson = req.body.json();
    if (rJson.code != 200) {
        let message = rJson.message ? rJson.message : "服务异常请联系客服！";
        toastLog(message)
        sleep(2000)
        exit()
        sleep(2000)
        ui.finish()
    } else {
        myLogFunc("服务成功注册！")
    }
}

// 主方法
function mainFunc(again) {
    主线程 = threads.start(function () {
        // 检查无障碍服务是否已经启用，如果没有启用则跳转到无障碍服务启用界面，并等待无障碍服务启动；当无障碍服务启动后脚本会继续运行。
        auto.waitFor()
        // 主线程启动
        myLogFunc("主线程启动")
        // 注册服务
        autoServerFunc()
        sleep(yanchi)
        //申请截屏权限
        if (!again) {
            //截图权限自动化安卓版本高于Android 9
            if (device.sdkInt > 27) {
                //等待截屏权限申请并同意
                threads.start(function () {
                    if (device.brand == "HUAWEI") {
                        packageName('com.android.systemui').text('允许').waitFor();
                        text('允许').click();
                    } else {
                        packageName('com.android.systemui').text('立即开始').waitFor();
                        text('立即开始').click();
                    }
                });
            }
            sleep(yanchi)
            if (!requestScreenCapture()) {
                toast("请求截图失败");
                exit()
            }
        }
        myLogFunc('分辨率:'+deviceWidth+"/"+deviceHeight)
        myLogFunc('分辨率基准:' + picJizhunWidth)
        //等待
        sleep(yanchi)
        myLogFunc("打开APP")
        // 打开app
        let appPackName = currentPackage();
        if (appPackName != appPackageName) {
            app.launchPackage(appPackageName);
            myLogFunc("正在运行请稍等")
            if (isPulic) {
                sleep(5000)
            } else {
                sleep(1000)
            }
            myLogFunc("程序运行中")
        } else {
            myLogFunc("正在运行红薯");
        }
        //等待
        sleep(1000)
        myLogFunc("开始程序流程")
        zhuyeLiuchengFunc()
        myLogFunc("结束程序流程")

    })
}

// 重置计数
ui.cleanCon.on("click", function () {
    storage.put("liulanNum", String("0"));
    storage.put("pinglunNum", String("0"));
    ui.liulanNum.text(String(storage.get("liulanNum", "0")));
    ui.pinglunNum.text(String(storage.get("pinglunNum", "0")));
})

// 清空配置
ui.cleanApp.on("click", function () {
    storages.remove('autotouchHongshu')
    toastLog('数据已清空，请关闭app重新打开配置')
})

// 点击启动程序
ui.start.on("click", function () {
    // 保存配置
    saveconfig()
    //程序开始运行之前判断无障碍服务
    if (auto.service == null) {
        toastLog("请先开启无障碍服务！");
        app.startActivity({
            action: "android.settings.ACCESSIBILITY_SETTINGS"
        });
        return;
    } else {
        log('已获取无障碍权限');
    }
    // 悬浮窗按钮
    if (!floaty.checkPermission()) {
        // 没有悬浮窗权限，提示用户并跳转请求
        toastLog("本脚本需要悬浮窗权限来显示悬浮窗，请在随后的界面中允许并重新运行本脚本。");
        floaty.requestPermission();
        return;
    } else {
        log('已获取悬浮窗权限');
    }
    // 激活码
    if (storage.get("jihuoma", "").length != 28) {
        toastLog("激活码错误，请打开系统设置选项验证激活码！");
        return;
    }
    // 开启悬浮窗
    xuanfuFunc()
    // 开启日志悬浮窗
    if (Boolean(storage.get("logWindow", false))) {
        xuanfuLogFunc()
        myLogFunc('打开日志窗口');
    }
    // 日志文件
    if (Boolean(storage.get("logFile", false))) {
        myLogFunc('日志文件: DaoyikejiXhs.txt');
        console.setGlobalLogConfig({
            "file": "/sdcard/DaoyikejiXhs.txt"
        });
    }
    // 格式化数据
    picJizhunHeight = deviceHeight / 2640;
    picJizhunWidth = deviceWidth / 1200;
    searchForList = storage.get("searchFor", "复合,租赁");
    searchForList = searchForList.split(',');
    pinglunsList = storage.get("pingluns", "");
    pinglunsListStr = pinglunsList;
    pinglunsList = pinglunsList.split(',');
    sixinReg = storage.get("sixinKeys", "有票|嘎嘎活");
    sixinReg = RegExp(sixinReg)
    pinglunReg = storage.get("pinglunKeys", "求求了|师傅|帮我|做了|推荐");
    pinglunReg = RegExp(pinglunReg)
    sixinCont = storage.get("sixinCont", "诚信来互有赞必回随迟必到，欢迎来互！");
    sousuofanye = Number(storage.get("sousuofanye", "5"));
    pinglunfanye = Number(storage.get("pinglunfanye", "5"));
    plxl = Number(storage.get("plxl", "50"));
    mainFunc()
});


function zhuyeLiuchengFunc() {
    // 防止程序卡死
    threads.start(function () {
        let jiancePoint = setTimeout(() => {
            myLogFunc('防异常程序检测')
            clearTimeout(jiancePoint)
            if (!true) {
                toastLog("程序异常，重启应用！")
                sleep(1000)
                openAppSetting(appPackageName);
                text(app.getAppName(appPackageName)).waitFor();//通过包名获取已安装的应用名称，判断是否已经跳转至该app的应用设置界面
                let is_sure = textMatches(/(.*强.*|.*停.*|.*结.*)/).findOne();//在app的应用设置界面找寻包含“强”，“停”，“结”，“行”的控件
                if (is_sure.enabled()) {//判断控件是否已启用（想要关闭的app是否运行）
                    sleep(500);
                    is_sure.click();//结束应用的控件如果无法点击，需要在布局中找寻它的父控件，如果还无法点击，再上一级控件，本案例就是控件无法点击
                    sleep(1000);
                    textMatches(/(.*确.*|.*定.*)/).findOne().click();//需找包含“确”，“定”的控件
                    myLogFunc("应用已被关闭");
                    sleep(1000);
                    back();
                    sleep(1000);
                    mainFunc();
                } else {
                    myLogFunc("应用不能被正常关闭或不在后台运行");
                    back();
                    exit();
                }
            }
            myLogFunc('定时器线程关闭了')
        }, 60000);
    })

    // 获取坐标
    myLogFunc('等待控件..')
    desc("搜索").waitFor()
    myLogFunc('发现控件')
    desc("搜索").findOne().click();
    text("搜索").waitFor()
    className("android.widget.EditText").findOne().click();
    sleep(yanchi1)
    className("android.widget.EditText").findOne().setText(storage.get("searchFor", "复合"));
    sleep(yanchi1)
    text("搜索").findOne().click();
    myLogFunc('等待搜索结果')
    sleep(yanchi2)
    // 搜索笔记结果
    for (let index = 0; index < sousuofanye; index++) {
        seeTieziFunc()
        sleep(1000)
        swipe(device.width * 0.6 + random(-20, 10), deviceHeight * 0.8 + random(-20, 10), device.width * 0.6 + random(-20, 10), deviceHeight * 0.3 + random(-20, 10), 1000);
        sleep(1000)
    }
    myLogFunc("流程结束")
}

// 查看帖子
function seeTieziFunc() {
    let pinglunlem = 0;
    // 查看未点赞帖子
    let thisImgs = images.read("./img/weidianzan.png");
    thisImgs = images.scale(thisImgs, picJizhunWidth, picJizhunWidth);
    let result = images.matchTemplate(captureScreen(), thisImgs, { threshold: 0.8, max: 6 });
    thisImgs.recycle();
    log('搜索结果:', result.matches)
    if (result.matches.length) {
        log("matchRc")
        let matchRc = result.sortBy("top-bottom").matches;
        log(matchRc)
        for (let index = 0; index < matchRc.length; index++) {
            // 先点击喜欢作为标注
            click(matchRc[index].point.x, matchRc[index].point.y);
            log(1)
            sleep(yanchi1)
            log(2)
            // 点击进入说说
            pinglunlem = 0;
            log(3)
            click(matchRc[index].point.x, matchRc[index].point.y - 200);
            log(4)
            let liulanNum = storage.get("liulanNum", "0")
            liulanNum = Number(liulanNum) + 1;
            storage.put("liulanNum", String(liulanNum));
            sleep(yanchi1)
            log(5)
            id("nickNameTV").waitFor()
            log(6)
            let nickName = id("nickNameTV").findOne().text()
            myLogFunc(nickName + "的帖子")
            swipe(device.width * 0.6 + random(-10, 10), deviceHeight * 0.8, device.width * 0.6 + random(-10, 10), deviceHeight * 0.3, 800);
            while (!textMatches("共.*条评论").exists()) {
                myLogFunc("评论区未出现")
                swipe(device.width * 0.6 + random(-10, 10), deviceHeight * 0.8, device.width * 0.6 + random(-10, 10), deviceHeight * 0.3, 800);
                sleep(1000)
            }
            myLogFunc("评论区出现了")
            swipe(device.width * 0.6 + random(-10, 10), deviceHeight * 0.8, device.width * 0.6 + random(-10, 10), deviceHeight * 0.3, 800);
            sleep(1000)
            let pinglunde = "";
            let sixinde = "";
            // 调整到评论区域
            for (let index = 0; index < pinglunfanye; index++) {
                sleep(1000)
                // 查看评论区包含回复的内容 --- 回复
                textEndsWith(" 回复").find().forEach(function (target1, index1) {
                    let texta = target1.text();
                    // 可能存在空元素
                    if (target1) {
                        // 评论的内容
                        let contStr = String(texta);
                        // 评论的位置
                        let bounds = target1.bounds();
                        // 判断是否在安全区
                        if (bounds.centerY() < anquanqu) {
                            // 私信流程
                            if (Boolean(storage.get("isSixin", false))) {
                                if (contStr.match(sixinReg)) {
                                    target1.parent().parent().findOne(id("dz5")).click();
                                    sleep(1000)
                                    if (sixinde.indexOf(contStr) == -1) {
                                        let ghn = id("ghn").findOne().text();
                                        sixinde = sixinde + ghn;
                                        sleep(500)
                                        desc("发消息").click();
                                        sleep(1000)
                                        sendMsg(sixinCont);
                                        while (!id("ww").exists()) {
                                            back()
                                            sleep(1000)
                                        }
                                    } else {
                                        myLogFunc('已私信过此人')
                                        back()
                                        sleep(1000)
                                    }
                                }
                            }
                            // 评论流程
                            if (Boolean(storage.get("isPinglun", true)) && Number(storage.get("pinglunNum", "0")) < plxl) {
                                if (contStr.match(pinglunReg)) {
                                    
                                    log("pinglunde",pinglunde)
                                    log("pinglunsListStr",pinglunsListStr)
                                    log("contStr",contStr)
                                    
                                    if (!pinglunde.includes(contStr) && !pinglunsListStr.includes(contStr)) {
                                        click(bounds.centerX(), bounds.centerY())
                                        sleep(1000)
                                        myLogFunc('评论：' + String(contStr))
                                        pinglunde = pinglunde + contStr;
                                        let sentText = getRandomNumber(0, pinglunsList.length - 1)
                                        sentText = pinglunsList[sentText]
                                        myLogFunc('回复：' + sentText)
                                        sendMsgHf(sentText);
                                        pinglunlem = pinglunlem + 1;
                                        let pinglunNum = storage.get("pinglunNum", "0")
                                        pinglunNum = Number(pinglunNum) + 1;
                                        storage.put("pinglunNum", String(pinglunNum));
                                        sleep(2000)
                                    } else {
                                        myLogFunc('已评论过此条')
                                    }

                                }
                            }
                        } else {
                            myLogFunc('安全区外内容', contStr)
                        }
                    }
                })
                sleep(yanchi)
                myLogFunc("翻页")
                swipe(device.width * 0.6 + random(-10, 10), deviceHeight * 0.8, device.width * 0.6 + random(-10, 10), deviceHeight * 0.3, 800);
                sleep(yanchi1)
            }
            sleep(yanchi1)
            back()
            sleep(yanchi1)
        }
    } else {
        sleep(yanchi)
        swipe(device.width * 0.6 + random(-10, 10), deviceHeight * 0.8, device.width * 0.6 + random(-10, 10), deviceHeight * 0.3, 800);
        sleep(yanchi1)
    }
}


// 函数方法

/**
 * 输入框发送 
 * @param {*} text 内容 输入的文字
 */
function sendMsg(text) {
    sleep(1000)
    className("android.widget.EditText").findOne().click();
    sleep(1000)
    className("android.widget.EditText").findOnce().setText(text);
    sleep(1500)
    let thisImgs = images.read("./img/fasong.png");
    thisImgs = images.scale(thisImgs, picJizhunWidth, picJizhunWidth);
    let pt = findImage(captureScreen(), thisImgs, { threshold: 0.88 });
    thisImgs.recycle();
    if (pt) {
        myLogFunc('发送')
        click(pt.x, pt.y)
        sleep(1000)
    } else {
        myLogFunc('未检测发送按钮')
    }
}

function sendMsgHf(text) {
    sleep(1000)
    className("android.widget.EditText").findOne().click();
    sleep(1000)
    className("android.widget.EditText").findOnce().setText(text);
    sleep(1500)
    let thisImgs = images.read("./img/fasong_lan.png");
    thisImgs = images.scale(thisImgs, picJizhunWidth, picJizhunWidth);
    let pt = findImage(captureScreen(), thisImgs, { threshold: 0.88 });
    thisImgs.recycle();
    if (pt) {
        myLogFunc('发送')
        click(pt.x, pt.y)
        sleep(1000)
    } else {
        myLogFunc('未检测发送按钮')
        back()
        sleep(1000)
    }
}

// 坐标验证
function 坐标验证(weight) {
    // 验证坐标是当前屏幕内容 
    if (weight.left > 0 && weight.right > 0 && weight.top > 0 && weight.bottom > 0 && weight.top < deviceHeight && weight.bottom < deviceHeight) {
        return true
    } else {
        return false
    }
}

// 获取随机数
function getRandomNumber(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}





